core: Error out cleanly if user attempts to commit an empty tree
authorColin Walters <walters@verbum.org>
Thu, 5 Jan 2012 23:27:21 +0000 (18:27 -0500)
committerColin Walters <walters@verbum.org>
Thu, 5 Jan 2012 23:27:21 +0000 (18:27 -0500)
src/ostree/ot-builtin-commit.c

index 329c82a48f7ff1070a442f5834625530796d0eeb..e414a2c1669b242f76eb54372292626c6c35cf95 100644 (file)
@@ -264,8 +264,17 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error)
 
   if (!skip_commit)
     {
+      const char *root_metadata = ostree_mutable_tree_get_metadata_checksum (mtree);
+      
+      if (!root_metadata)
+        {
+          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                       "Can't commit an empty tree");
+          goto out;
+        }
+
       if (!ostree_repo_stage_commit (repo, branch, parent, subject, body, metadata,
-                                     contents_checksum, ostree_mutable_tree_get_metadata_checksum (mtree),
+                                     contents_checksum, root_metadata,
                                      &commit_checksum, cancellable, error))
         goto out;